<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
     <%@page import="com.pojo.User"%>
     <%@page import="com.Dao.SubDao"%>
     <%@page import="com.Dao.UserDao"%>
     <%@page import="com.pojo.Sub"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

    <head>
    <meta charset="UTF-8">
<title>个人中心</title>
    <link rel="stylesheet" href="css/index.css" type="text/css">
    <script src="js/jquery.js"></script>
</head>
<% 
String up = ((User)session.getAttribute("user")).getUphone();
UserDao userDao = new UserDao();
User result = userDao.findUserByUsery(up);
session.setAttribute("user",result);
Integer uid = ((User)session.getAttribute("user")).getUid();
%>
<body>
<div class="warp">
<div class="fanhui">
<a href="../controller/return.jsp">返回</a></div>
    <div class="information">
        <h1 style="text-align: center">个人中心</h1>
        <div class="information-left">
    <div style="width:214px;hegiht:214px;" class="hp" >
    <input type="file" id="fileUp" accept="image/png,image/jpeg,image/jpg" style="display:none;">
    <% String image = userDao.findpassword(uid);%>
	<div id="sy"><img style="width: 214px;height: 214px;border-radius:100%;"src="../file/<%=image %>" onclick="load()"></div>
    </div>
    <div class="explain" id="chhh">
<div  id="qm"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%=((User)session.getAttribute("user")).getUexplain() %></span></div>
        <div class="xgan" style="margin: 5px auto;" id="ch"><span style="font-size: 20px;">修改</span></div>
            </div>
            <div class="explain xge" id="chh">
                
                <input class="input" type="text" Name="Uid" id="Uid" style="display: none;" value="<%=((User)session.getAttribute("user")).getUid()%>"/>
                    <input class="input1" type="text" Name="Uexplain" id="Uexplain" placeholder="签名" required=""  autocomplete="off"/><br/>
                    
                
                <button onclick="getClk1()">提交</button>
            </div>
        </div>
        <div class="information-right" >
            <div class="xinxi xx" id="aqqq">
            <table STYLE="text-align: center;" id="tb1">
                <tr><td style="width: 80px;">昵称:</td><td class="td"><%=((User)session.getAttribute("user")).getUname() %></td></tr>
                <tr><td style="width: 80px;">性别:</td><td class="td"><%=((User)session.getAttribute("user")).getUsex() %></td></tr>
                <tr><td style="width: 80px;">生日:</td><td class="td"><%=((User)session.getAttribute("user")).getUage() %></td></tr>
                <tr><td style="width: 80px;">邮箱:</td><td class="td"><%=((User)session.getAttribute("user")).getUemail() %></td></tr>
                <tr><td style="width: 80px;">住址:</td><td class="td"><%=((User)session.getAttribute("user")).getUhome() %> </td></tr>

            </table>
                <div class="xgan" id="aq"><span>修改</span></div>
            </div>
            <div class="xinxi  xg" id="aqq">
                <form style="margin-left: 5px;width: 80%" id="sy">
                	<input class="input" type="text" Name="Uid" id="Uid" style="display: none;" value="<%=((User)session.getAttribute("user")).getUid()%>"/>
                	<span></span>
                    <input class="input" type="text" Name="Uname" id="Uname" placeholder="<%=((User)session.getAttribute("user")).getUname() %>"  value="<%=((User)session.getAttribute("user")).getUname() %>" required=""  autocomplete="off"/><br/>
					<span></span>
                    <input id="man" type="radio" checked="checked" name="Usex" value="男"  autocomplete="off"/>男<input id="woman" type="radio"  name="Usex" value="女" autocomplete="off"/>女
					<br/>
					<input class="input" type="text" Name="Uage" id="Uage" placeholder="<%=((User)session.getAttribute("user")).getUage() %>" value="<%=((User)session.getAttribute("user")).getUage() %>" required=""  autocomplete="off"/>
                    <span></span>
                    <input class="input" type="text" Name="Uemail" id="Uemail" placeholder="<%=((User)session.getAttribute("user")).getUemail() %>" value="<%=((User)session.getAttribute("user")).getUemail() %>" required=""  autocomplete="off"/>
					<span></span>
                    <input class="home" type="text" Name="Uhome" id="Uhome" placeholder="<%=((User)session.getAttribute("user")).getUhome() %>" value="<%=((User)session.getAttribute("user")).getUhome() %>" required=""  autocomplete="off"/><br/>
                    <span></span>
                    
                
                <span></span>
                </form>
                <button  onclick="getClk2()">提交</button>
            </div>
        </div>
    </div>
    <div class="my">
        <h1 style="text-align: center">我的帖子</h1>
        		 <%
        		 Integer UId =((User)session.getAttribute("user")).getUid();
        		
						SubDao SubDao = new SubDao();
						Sub[] subArr = SubDao.mycards(UId);
						for (int i = 0; i < SubDao.getSubCounta(); i++) {
					%>	
		<a href="${pageContext.request.contextPath}/text.jsp?SId=<%=subArr[i].getSId()%>">
        <div style="width:880px;background:#98f4fd80;">
        	<div style="float:left;width: 150px;height:80px;text-align: center;line-height: 80px;"><%=subArr[i].getTheme()%></div>
        	<div style="float:left;width: 580px;height:80px;text-align: center;line-height: 80px;"><%=subArr[i].getTitlel()%></div>
        	<div style="float:left;width: 150px;height:80px;text-align: center;line-height: 80px;"><%=subArr[i].getTime()%></div>
        	<div style="clear: both;"></div>
        </div>
        </a>
        <br/>
        <%
        } 
        %>	
    </div>
</div>
<script src="js/index.js"></script>
<script type="text/javascript">
function load() {
	const BTN2 = document.getElementById('fileUp');
	BTN2.click();
}
var fileM=document.querySelector("#fileUp");
$("#fileUp").on("change",function() {
    //获取文件对象，files是文件选取控件的属性，存储的是文件选取控件选取的文件对象，类型是一个数组
    var fileObj = fileM.files[0];
    //创建formdata对象，formData用来存储表单的数据，表单数据时以键值对形式存储的。
    var formData = new FormData();
    formData.append('file', fileObj);
    $.ajax({
        url: "${pageContext.request.contextPath }/controller/uploadx.jsp",
        type: "post",
        dataType: "json",
        data: formData,
        async: false,
        cache: false,
        contentType: false,
        processData: false,
        success: function (json_data) {
            alert("恭喜你！上传成功");
            var str ="";
            str+='<img style="width: 214px;height: 214px;border-radius:100%;"src="../file/'+json_data+'" onclick="load()">';
			document.getElementById('sy').innerHTML=str;
        },
    });
    
});

			
function getClk2() {
	var Uid = $(" #Uid").val() ;
	var Uname = $("#Uname").val() ;
	var Usex = $('input:radio[name="Usex"]:checked').val();
	var Uage = $(" #Uage ").val() ;
	var Uemail = $(" #Uemail ").val() ;
	var Uhome= $(" #Uhome ").val() ;

	
	$.post("${pageContext.request.contextPath }/procCtry",
			{Uid:Uid,Uname:Uname,Usex:Usex,Uage:Uage,Uemail:Uemail,Uhome:Uhome},
	    	function(data){
					var str ="";
						str+='<tr><td style="width: 80px;">昵称:</td><td class="td">'+data.Uname+'</td></tr>';
	                    str+='<tr><td style="width: 80px;">性别:</td><td class="td">'+data.Usex+'</td></tr>';
	                    str+='<tr><td style="width: 80px;">生日:</td><td class="td">'+data.Uage+'</td></tr>';
	                    str+='<tr><td style="width: 80px;">邮箱:</td><td class="td">'+data.Uemail+'</td></tr>';
	                    str+=' <tr><td style="width: 80px;">住址:</td><td class="td">'+data.Uhome+'</td></tr>';

					document.getElementById('tb1').innerHTML=str;
	        },"json"
	);
	document.getElementById('aqqq').style.display='block';
    document.getElementById('aqq').style.display='none';
};
function getClk1() {
	var Uid = $(" #Uid").val() ;
	var Uexplain = $(" #Uexplain").val() ;
	$.post("${pageContext.request.contextPath }/ProcCx2",
			{Uid:Uid,Uexplain:Uexplain},
	    	function(data){
					var str ="";
						str+='<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+data.Uexplain+'</span>';
					document.getElementById('qm').innerHTML=str;
	        },"json"
	);
	 document.getElementById('chhh').style.display='block';
	    document.getElementById('chh').style.display='none';
};
</script>
</body>
</html>